package com.glory.cqaospda.utils;

import android.util.Log;

import com.glory.cqaospda.base.Constant;
import com.glory.cqaospda.bean.HeaderBean;
import com.glory.cqaospda.model.BaseRepository;
import com.glory.cqaospda.model.BaseRequest;
import com.glory.cqaospda.model.NetRequestBean;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.request.PostRequest;
import com.pda.platform.ui.ui_pdaplatform.callback.FreeUI_EntityCallBack;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_LogUtils;
import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_NetUtils;

import org.apache.commons.lang3.StringEscapeUtils;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;


/**
 * @author yi.zhang
 * @date 2019/6/10
 * @desc 网络请求类
 */
public class NetUtils {

    public static <T> void requestPostNet(String messageName, String method,Object tag, JsonObject jsonString,FreeUI_EntityCallBack<T> callBack){

        NetRequestBean netRequestBean = new NetRequestBean();
        netRequestBean.setBody(jsonString);
        netRequestBean.setHeader(new HeaderBean(messageName));
        BaseRequest baseRequest = new BaseRequest();
        baseRequest.setRequest(netRequestBean);

        Map<String,String> map = new HashMap<>();

////        map.put("senderId","EAP2CPCSender");
        map.put("",StringEscapeUtils.unescapeJson(new Gson().toJson(baseRequest)));
//        map.put("timeOut","50000");
        Log.e("requestData", "requestData: " + map);
//        FreeApi_LogUtils.saveErrorMessages(StringEscapeUtils.unescapeJson(new Gson().toJson(map)),"请求json");
        FreeApi_LogUtils.saveErrorMessages(Constant.Companion.getHttp() + Constant.Companion.getMUrl() + Constant.Companion.getAOSPDA() + method,"请求地址：");
        FreeApi_LogUtils.saveErrorMessages(map.toString(),"请求json");
        (((PostRequest) OkGo.post(Constant.Companion.getHttp() + Constant.Companion.getMUrl() + Constant.Companion.getAOSPDA() + method).tag(tag)).params(StringEscapeUtils.unescapeJson(new Gson().toJson(baseRequest)),0, new boolean[]{true})).execute(callBack);

//        FreeApi_NetUtils.requestPostNet(Constant.Companion.getHttp() + Constant.Companion.getMUrl() + Constant.Companion.getAOSPDA() + method, tag, map, callBack);
//        FreeApi_NetUtils.requestPostNet( Constant.REQUEST_URL_DEBUG + "/esbrest/RestService/postrequest", tag, map, callBack);

//         ((PostRequest) OkGo.post(Constant.REQUEST_URL_DEBUG).tag(tag))
//                .upJson(StringEscapeUtils.unescapeJson(new Gson().toJson(requestMessage))).execute(callBack);

    }

}
